package com.spontaneapp.adapters;

import java.util.ArrayList;

import com.spontaneapp.R;
import com.spontaneapp.classes.NavDrawerItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class NavDrawerListAdapter extends BaseAdapter {

	//State
	@SuppressWarnings("unused")
	private Context context;
    private ArrayList<NavDrawerItem> navDrawerItems;
    private LayoutInflater inflater;
    
    //Constructors
    public NavDrawerListAdapter(Context context, ArrayList<NavDrawerItem> navDrawerItems){
    	this.inflater = LayoutInflater.from(context);
        this.context = context;
        this.navDrawerItems = navDrawerItems;
    }
    
    //Methods
	@Override
	public int getCount() {
		return navDrawerItems.size();
	}

	@Override
	public Object getItem(int position) {
		return navDrawerItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public class NavDrawerListHolder{
		ImageView icon;
		TextView title;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		NavDrawerListHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.nav_drawer_list_item, parent, false);
			holder = new NavDrawerListHolder();
			holder.icon = (ImageView)convertView.findViewById(R.id.nav_drawer_list_item_icon);
			holder.title = (TextView)convertView.findViewById(R.id.nav_drawer_list_item_title);
			convertView.setTag(holder);
        }
		else
			holder = (NavDrawerListHolder) convertView.getTag();

		holder.icon.setImageResource(navDrawerItems.get(position).getIcon());        
        holder.title.setText(navDrawerItems.get(position).getTitle());
         
        return convertView;
    }
	
}
